import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)
const bcUser = JSON.parse(localStorage.getItem('bcUser'))
const state = {
  workType: '',
  workId:'',
  bcUser: bcUser || {},
}
const mutations = {
  setId(state, workId){
    state.workId = workId
  },
  setType(state, workType){
    state.workType = workType
  },
  setUser(state, bcUser){
    localStorage.setItem('bcUser', JSON.stringify(bcUser))
    Object.assign(state, bcUser)
  },
  removeUser(state, user){
    localStorage.removeItem(user);
    state.bcUser = {}
  }

}
const actions = {
  setId({commit}, workId) {
    commit('setId', workId)
  },
  setType({commit}, workType) {
    commit('setType', workType)
  },
  setUser({commit}, bcUser) {
    commit('setUser', bcUser)
  },
  removeUser({commit}, user) {
    commit('removeUser', user)
  }
}

export default new Vuex.Store({
  state,
  mutations,
  actions
})





